package com.example.finalwork.controller;


import com.example.finalwork.model.Paper;
import com.example.finalwork.service.PaperService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.HttpStatusCode;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("/papers")
public class PaperController {

    @Autowired
    private PaperService paperService;

    @GetMapping
    public String viewPapers(Model model) {
        model.addAttribute("papers", paperService.findAll());
        return "papers";
    }

    @PostMapping
    @ResponseBody
    public ResponseEntity<Paper> addPaper(@RequestBody Paper paper){
        Paper newPaper = paperService.addPaper(paper);
        return ResponseEntity.ok(newPaper);
    }
    @DeleteMapping("/{id}")
    @ResponseBody
    public ResponseEntity<Void> deletePaper(@PathVariable Long id){
        paperService.deletePaper(id);
        return ResponseEntity.noContent().build();
    }
}



